/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.report.loan;

import java.math.BigDecimal;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import src.domain.loan.Loan;
import src.services.loan.LoanModel;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class RptRiwayatKreditDataSource implements JRDataSource{
    private int index = -1; 
    private List<Loan> loans;
    private LoanModel helper;

    public RptRiwayatKreditDataSource() {
        helper = new LoanModel();    
        loans = helper.findAll(null);
    }
    
    
    
    @Override
    public boolean next() throws JRException {
        index++;
        //return (index < data.length);
        return (index < loans.size());
    }

    @Override
    public Object getFieldValue(JRField jrf) throws JRException {
         Object value = null;
         String fieldName = jrf.getName();
         /*
          * <field name="no_rek" class="java.lang.String"/>
	<field name="nm_nasabah" class="java.lang.String"/>
	<field name="bunga" class="java.math.BigDecimal"/>
	<field name="pajak" class="java.math.BigDecimal"/>
	<field name="administrasi" class="java.math.BigDecimal"/>
	<field name="saldo" class="java.math.BigDecimal"/>
	<field name="sum_bunga" class="java.math.BigDecimal"/>
	<field name="sum_pajak" class="java.math.BigDecimal"/>
	<field name="sum_administrasi" class="java.math.BigDecimal"/>
	<field name="sum_saldo" class="java.math.BigDecimal"/>
          */
         switch (fieldName) {
             case "rekening" : value = loans.get(index).getCustomer().getCif();break;
             case "nm_nasabah" : value = loans.get(index).getCustomer().getCustomerName();break;
        
             case "bunga" : value = new BigDecimal(0.00);break;
             case "pajak" : value = new BigDecimal(0.00);break;
             case "administrasi" : value = new BigDecimal(0.00);break;
             case "saldo" : value = new BigDecimal(0.00);break;
             case "sum_bunga" : value = new BigDecimal(0.00);break;
             case "sum_pajak" : value = new BigDecimal(0.00);break;
             case "sum_administrasi" : value = new BigDecimal(0.00);break;
             case "sum_saldo" : value = new BigDecimal(0.00);break;
         }
         return value;
    }
    
}
